package com.feng.zhihao.demo.sm2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import com.feng.zhihao.demo.sm2.util.SM2Utils;
import com.feng.zhihao.demo.sm2.util.Util;

public class Test {
	public static void main(String[] args) throws UnsupportedEncodingException, IOException {
		SM2Utils sm2Utils=new SM2Utils();
		System.out.println("puk:"+sm2Utils.getPublicKey());
		System.out.println("prk:"+sm2Utils.getPrivateKey());
		String name="你好";
		
		System.out.println("原文：" + name);
		
		String en = sm2Utils.encrypt(name.getBytes("UTF-8"));
		System.out.println("密文：" + en);
		System.out.println("原文：" + new String(sm2Utils.decrypt(Util.hexToByte(en)), "UTF-8"));
		
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));  
		while(true) {
			String s=bufferedReader.readLine();
			System.out.println("原文：" + new String(sm2Utils.decrypt(Util.hexToByte(s)), "UTF-8"));
		}
	}
}
